package websocket.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.List;

/**
 * 数据返回最外层封装对象(不分页多行数据)
 *
 * @author wangfei
 * @version v1.0
 * @since 2019/7/20 2:52
 */
@ApiModel(value = "数据返回-多行数据")
@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class ResultList<T> implements Serializable {
    /**
     * 状态值
     */
    @ApiModelProperty(name = "code", value = "状态值:0 – 处理成功，403 - 鉴权失败，500 - 系统错误，503 - 参数错误")
    private Integer code;

    /**
     * 提示
     */
    @ApiModelProperty(name = "message", value = "提示")
    private String message ;

    /**
     * 返回数据
     */
    @ApiModelProperty(name = "data", value = "返回数据")
    private List<T> data;

    private ResultList(ResultEnum resCode, List<T> data) {
        this.code = resCode.getCode();
        this.message = resCode.getMessage();
        this.data = data;
    }


    /**
     * 请求成功
     * @param data 数据
     * @param <T>
     * @return
     */
    public static <T> ResultList<T> success(List<T> data) {
        return new ResultList<T>(ResultEnum.success, data);
    }

    /**
     * 请求失败,系统异常
     * @param <T>
     * @return
     */
    public static <T> ResultList<T> systemError() {
        return new ResultList<T>(ResultEnum.SYSTEM_ERROR,null);
    }

    /**
     * 请求失败,参数错误
     * @param <T>
     * @return
     */
    public static <T>  ResultList<T> paramError() {
        return new ResultList<T>(ResultEnum.PARAM_ERROR,null);
    }

    @ApiModelProperty(name = "pageDate", value = "返回数据")
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
}
